package gui;

/**
 * Imports
 */
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * produces the main-Window with the playing field 
 * and with all of the menu entries which start the game, etc.
 * 
 * @author Psykoman
 *
 *@version 0.1 (17.06.2009)
 */
public class mainWindow extends Frame {
	Image img;
	
	/**
	 * settings for the menu-Bar 
	 * 
	 * @return menuBar 
	 */
	protected MenuBar setMenu() {
		MenuBar menu = new MenuBar();					//main Menu
		
		/**
		 * Menu entries
		 */
		Menu game = new Menu("Game");	
		Menu help = new Menu("Hilfe");
		Menu about = new Menu("About");
		
		/**
		 * Menu Items for Menu strg (Steuerung)
		 */
		MenuItem single_player = new MenuItem("Single Player");
		MenuItem exit = new MenuItem("Exit");
		game.add(single_player);
		game.addSeparator();
		game.add(exit);
		
		/**
		 * menu compilation
		 */
		menu.add(game);
		menu.add(help);
		menu.add(about);
		
		return menu;
	}
	
	/**
	 * beenden eines Fesnsters
	 * 
	 * @author Psykoman
	 *
	 */
	class TestWindowListener extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			e.getWindow().dispose(); 	// Fenster "killen"
			System.exit(0); 			// VM "killen"
		}
	}
	
	/**
	 * load the image
	 */
	public void load(Graphics g) {
		if(img != null)
			g.addImage(img, 100, 100, this);
	    else
		    g.clearRect(0, 0, getSize().width, getSize().height);
	}
	
	/**
	 * initialization of the main Window
	 * 
	 * @param x_range the width of the window
	 * @param y_range the height of the window
	 */
	public mainWindow(int x_range, int y_range) {
		MediaTracker mt = new MediaTracker(this);
	
		setTitle("Tower Defense");
		setSize(x_range, y_range);		
		setMenuBar(this.setMenu());
	    img = Toolkit.getDefaultToolkit().getImage("bsd-windows-linux.jpg");
	    mt.addImage(img, 0);
		addWindowListener(new TestWindowListener());
		
		setVisible(true);
	}

	
	 
		public static void main(String[] args) {
			// TODO Auto-generated method stub
			new mainWindow(640, 400);
		}

}
